﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Text;
using System.Data;

namespace PeisongWeb
{
    public partial class companyInfo : System.Web.UI.Page
    {
        protected string reUrl
        {
            get { return ViewState["reUrl"].ToString(); }
            set { ViewState["reUrl"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["reUrl"] != null)
                {
                    reUrl = Request.QueryString["reUrl"];
                }
                else
                {
                    reUrl = "index.html";
                }
                drpBind();
            }
        }
        private void drpBind()
        {
            ddl_Area.DataSource = logic.sysCode.areaList();
            ddl_Area.DataBind();
        }
        protected void lbtn_reg_Click(object sender, EventArgs e)
        {
            CompanyEntity cp = new CompanyEntity();
            cp.Company = txt_companyName.Value;
            cp.CompanyNo = "";
            cp.Soruce = "2";
            cp.Address = txt_Address.Text;
            cp.AreaID = Convert.ToInt32(ddl_Area.SelectedValue);
            cp.Contact = txt_contact.Value;
            cp.Email = txt_Email.Value;
            cp.EatPerson = txt_eatPerson.Value.Trim();
            cp.Fax = txt_fax.Value;
            cp.Location = txt_location.Value;
            cp.Mobile = txt_Mobile.Value;
            cp.Phone = txt_phone.Value;
            cp.Postcode = txt_postCode.Value;
            cp.Type = hd_type.Value;
            cp.IsCheck = false;
            cp.buyerType = "1";//普通采购商
            logic.company.insert(cp);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "regSuccess();", true); 
        }

        protected void lbtn_Login_Click(object sender, EventArgs e)
        {
            string userName = txt_userName.Value;
            string passWord = txt_pwd.Value;

            if (!String.IsNullOrEmpty(userName) && !String.IsNullOrEmpty(passWord))
            {
                DAL.CustomerEntity cusomter = logic.customer.login(userName, Library.StringLbl.EncryptMD5(passWord));
                if (cusomter.CustomerId != 0)
                {
                    logic.customer.userId = cusomter.CustomerId;
                    Response.Redirect(reUrl);
                }
                else
                {
                    Library.Script.ClientMsg("［用户名］或［密码］不正确，或者是有效期已过，请重试 或 与 客服 联系。");
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "showDiv();", true); 
                    return;
                }
            }
        }
    }
}
